package com.ruoyi.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.business.entity.YytMember;
import com.ruoyi.common.business.service.YytMemberService;
import com.ruoyi.common.pms.dao.YytShopMemberMapper;
import com.ruoyi.common.pms.entity.YytShop;
import com.ruoyi.common.pms.service.YytShopService;
import com.ruoyi.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.pms.entity.YytShopMember;
import com.ruoyi.common.pms.service.YytShopMemberService;

import javax.annotation.Resource;

/**
* <p>
    *  前端控制器
    * </p>
*
* @author MrPing
* @since 2022-05-19
*/
@RestController
@RequestMapping("/userShop")
public class YytShopMemberController{

    @Resource
    private YytShopMemberMapper yytShopMemberMapper;

    @Autowired
    private YytMemberService yytMemberService;

    @Autowired
    private YytShopService yytShopService;

    /**
     * 根据用户微信id 获取是否是管理员
     * @param wechatId
     * @return
     */
    @GetMapping("/getMySysShopList")
    public ResponseResult getMySysShopList(@RequestParam("wechatId") String wechatId){
        return ResponseResult.success(yytShopMemberMapper.isShopSys(wechatId));
    }

    /**
     * 配送员绑定店铺
     * @param yytMember
     * @return
     */
    @PostMapping("/shopBinding")
    public ResponseResult shopBinding(@RequestBody YytMember yytMember){
        yytMemberService.updateById(yytMember);
        YytShop yytShop = yytShopService.getById(yytMember.getShopId());
        YytShopMember yytShopMember = new YytShopMember();
        yytShopMember.setMemberId(yytMember.getId());
        yytShopMember.setShopId(yytMember.getShopId());
        yytShopMember.setShopName(yytShop.getShopName());
        yytShopMember.setAuthStatus("2");
        yytShopMember.setWechatId(yytMember.getWechatId());
        yytShopMember.setPassStatus(0);
        return ResponseResult.success(yytShopMemberMapper.insert(yytShopMember));
    }

}
